<template>
  <!-- 放置一个图标 -->
  <div class="screenWrapper">
    <svg-icon
      :icon-class="isFull ? 'exit-fullscreen' : 'fullscreen'"
      class="fullscreen"
      @click="toggleScreen"
    />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFull: false
    }
  },
  mounted() {
    screenfull.on('change', () => {
      this.isFull = screenfull.isFullscreen
    })
    // 验证码登录
  // 前端调用一个我们自己的后端接口
  // 我们自己的后端去调用一个三方的负责发送验证码的接口
  // 定时器等待接收
    // document.addEventListener('fullscreenchange', () => {
    //   // 判断一下当前是否是全屏状态 如果是非全屏状态 isFull重置为false
    //   const isFull = document.fullscreenElement
    //   // console.log(isfull)
    //   isFull ? null : this.isFull = false
    //   // if (isFull === null) {
    //   //   this.isFull = false
    //   // }
    // })
  },
  methods: {
    toggleScreen() {
      if (screenfull.isEnabled) {
        screenfull.toggle()
      }
      // 可能不兼容其他浏览器
      // if (this.isFull) {
      //   document.exitFullscreen()
      // } else {
      //   document.documentElement.requestFullscreen()
      // }
      // this.isFull = !this.isFull
    }
  }
}
</script>

<style lang="scss" scoped>
.screenWrapper {
  display: flex;
  align-items: center;
  margin-right: 20px;
}
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
